package org.achievement.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.achievement.system.common.RequestResult;
import org.achievement.system.dao.ScoreDao;
import org.achievement.system.pojo.entity.Score;
import org.achievement.system.service.ScoreService;

import org.achievement.system.pojo.form.ScoreForm;
import org.achievement.system.pojo.vo.ScoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreDao, Score> implements ScoreService {

    @Autowired
    private ScoreDao scoreDao;

    @Override
    public RequestResult list(ScoreForm scoreForm) {
        if (scoreForm != null) {
            if (scoreForm.getPageSize() == null || scoreForm.getPageSize() <= 0) {
                scoreForm.setPageSize(10);
            }
            int offset = (scoreForm.getPage() - 1) * scoreForm.getPageSize();
            scoreForm.setOffset(offset);
        }
        List<ScoreVo> list = scoreDao.list(scoreForm);
        Integer totalSize = scoreDao.count(scoreForm);
        HashMap<String, Object> resultData = new HashMap<>();
        resultData.put("list", list);
        resultData.put("totalSize", totalSize);
        return RequestResult.success(resultData);
    }
}